package com.caojing.haolemai.ui.category.categoryadapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.caojing.haolemai.R;
import com.caojing.haolemai.bean.categorybean.BrandCategoryBean;

import java.util.List;

/**
 * Created by My on 2016/10/18.
 */
public class CategoryLightHeaderAdapter extends RecyclerView.Adapter<CategoryLightHeaderAdapter.MyViewHolder> {

    private Context mContext;
    private List<BrandCategoryBean> beanList;

    //回调接口
    public interface OnRecyclerViewItemClickListener {
        void onItemClickListener(View view, int position);
    }
    //初始化接口对象
    private static OnRecyclerViewItemClickListener mListener;

    public void setOnRecyclerViewItemClickListener(OnRecyclerViewItemClickListener listener) {
        mListener = listener;
    }

    public CategoryLightHeaderAdapter(Context context,List<BrandCategoryBean> beanList){
            this.mContext=context;
            this.beanList=beanList;
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

        private ImageView category_right_iv_brand_logo;
        private TextView tv_category_brand_name_item;
        public MyViewHolder(View itemView) {
            super(itemView);
            category_right_iv_brand_logo= (ImageView) itemView.findViewById(R.id.category_right_iv_brand_logo);
            tv_category_brand_name_item= (TextView) itemView.findViewById(R.id.tv_category_brand_name_item);
         itemView.setOnClickListener(this);
        }


        @Override
        public void onClick(View v) {
            mListener.onItemClickListener(v, getAdapterPosition());
        }
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.category_right_recycler_item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        BrandCategoryBean brandCategoryBean = beanList.get(position);
        Glide.with(mContext).load(brandCategoryBean.getBrandPicture()).into(holder.category_right_iv_brand_logo);
        holder.tv_category_brand_name_item.setText(brandCategoryBean.getBrandName());
    }

    @Override
    public int getItemCount() {
        return beanList.size();
    }


}
